package com.kye.express.business.order.remark;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.kye.express.R;
import com.kye.express.view.reclyerview.OnItemClickListener;

import me.drakeet.multitype.ItemViewBinder;

public class RemarkViewBinder extends ItemViewBinder<String, RemarkViewBinder.ViewHolder> {

    private OnItemClickListener<String> mOnItemClickListener;


    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_remark, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull String string) {
        holder.bind(string);
    }

    @Override
    protected long getItemId(@NonNull String item) {
        return item.hashCode();
    }

    public OnItemClickListener<String> getOnItemClickListener() {
        return mOnItemClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener<String> onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private String mData;

        ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnItemClickListener == null) return;
                    mOnItemClickListener.onClickItem(mData, view);
                }
            });
        }

        public void bind(String data) {
            mData = data;
            ((TextView) itemView).setText(data);
        }
    }
}
